package com.skycong.hello77.activity.order;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import com.skycong.hello77.R;
import com.skycong.hello77.activity.mydialogcar.MyProgressDialog_car;
import com.skycong.hello77.activity.personhome.PersonHomeActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.skycong.hello77.R.id.list_order_view;

public class OrderActivity extends Activity implements View.OnClickListener{

    private Spinner spinner;
    private ArrayAdapter<String> arr_adapter;
    private SimpleAdapter simpleAdapter;
    private List<Map<String,Object>> orderData;
    private List<String> spinnerData;
    private ListView orderListView;

    private RadioButton distribution;//已配送
    private RadioButton waitSend;//待配送
    private ImageView imgBack;//返回箭头
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);


        distribution = (RadioButton) findViewById(R.id.distribution);
        waitSend = (RadioButton) findViewById(R.id.wait_send);
        spinner = (Spinner) findViewById(R.id.spinner);
        orderListView = (ListView) findViewById(R.id.list_order_view);
        imgBack = (ImageView) findViewById(R.id.img_back);
        spinnerData = new ArrayList<String>();
        orderData = new ArrayList<Map<String, Object>>();

        distribution.setOnClickListener(this);
        waitSend.setOnClickListener(this);
        imgBack.setOnClickListener(this);
        /*
         * 为spinner设置数据源
         * */
        spinnerData.add("01-10【18:01】");
        spinnerData.add("01-10【18:01】");
        spinnerData.add("01-10【18:01】");
        spinnerData.add("01-10【18:01】");
//        arr_adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,spinnerData);
//        arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//        spinner.setAdapter(arr_adapter);


       // 订单列表
        simpleAdapter = new SimpleAdapter(this,getdata(),R.layout.list_order_item,new String[]{"order_text","time_text"},new int[]{R.id.order_text,R.id.time_text});
        orderListView.setAdapter(simpleAdapter);

    }
    /**
     * 按钮点击之间的切换
     * */
    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id){
            case R.id.distribution:{
                distribution.setTextColor(Color.BLACK);
                waitSend.setBackground(getDrawable(R.drawable.radion_select));
                waitSend.setTextColor(Color.WHITE);

                break;
            }
            case R.id.wait_send:{
                distribution.setTextColor(Color.WHITE);
                distribution.setBackground(getDrawable(R.drawable.radion_select));
                waitSend.setTextColor(Color.BLACK);
                break;
            }
            case R.id.img_back:{
                Intent intent = new Intent(OrderActivity.this, PersonHomeActivity.class);
                OrderActivity.this.startActivity(intent);
                break;
            }
        }

    }

    public List<Map<String,Object>> getdata() {
        for(int i=0;i<10;i++){
            Map<String,Object> map = new HashMap<String, Object>();
            map.put("order_text","订单号：456123789");
            map.put("time_text",System.currentTimeMillis());
            orderData.add(map);
        }
        return orderData;
    }
}
